package com.lwb.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lwb.commonutils.Row;
import com.lwb.educms.entity.CrmBanner;
import com.lwb.educms.service.CrmBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 后台管理系统
 * </p>
 *
 * @author testjava
 * @since 2020-12-01
 */
@RestController
@RequestMapping("/educms/bannerAdmin")
@CrossOrigin
public class CrmBannerAdminController {

    @Autowired
    private CrmBannerService crmBannerService;

    //1. 分页查询
    @GetMapping("/findAllBannerByPage/{page}/{limit}")
    public Row findAllBannerByPage(@PathVariable long page,@PathVariable long limit){
        Page<CrmBanner> pageBanner = new Page<CrmBanner>(page,limit);
        crmBannerService.page(pageBanner,null);
        return Row.SUCCESS().data("pagelist",pageBanner.getRecords()).data("total",pageBanner.getTotal());
    }

    //2. 添加banner
    @PostMapping("addBanner")
    public Row addBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.save(crmBanner);
        return Row.SUCCESS();
    }

    //3. 根据id查询
    @GetMapping("findBannerById/{id}")
    public Row findBannerById(@PathVariable String id){
        CrmBanner crmBanner = crmBannerService.getById(id);
        return Row.SUCCESS().data("crmBanner",crmBanner);
    }

    //4. 修改banner
    @PostMapping("updateBanner")
    public Row updateBanner(@RequestBody CrmBanner crmBanner){
        crmBannerService.updateById(crmBanner);
        return Row.SUCCESS();
    }

    //5. 删除banner
    @DeleteMapping("deleteBanner/{id}")
    public Row deleteBanner(@PathVariable String id){
        crmBannerService.removeById(id);
        return Row.SUCCESS();
    }


}

